/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.siagefi.controller;

import br.siagefi.util.FacesUtil;
import java.io.IOException;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Paulo Lavarini
 */

@ManagedBean
@SessionScoped
public class LoginBean implements Serializable{
    
    @Inject
    private FacesContext facesContext;
    
    @Inject
    private HttpServletRequest request;
    
    @Inject
    private HttpServletResponse response;
    
    private String login;
    
    public void preRender(){
        if("true".equals(request.getParameter("invalid"))){
            FacesUtil.addErrorMessage("Usuario ou senha invalido!");
        }
    }
    
    public void logar() throws ServletException, IOException{
        RequestDispatcher dispatcher = request.getRequestDispatcher("/j_spring_security_check");
        dispatcher.forward(request, response);
        
        facesContext.responseComplete();
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }
    
    
}
